import com.sap.smb.sbo.api.ICompany;
import com.sap.smb.sbo.api.IRecordset;
import com.sap.smb.sbo.api.SBOCOMUtil;
import com.sap.smb.sbo.api.SBOErrorMessage;

/**
 * Created by IntelliJ IDEA.
 * User: mlv
 * Date: 2013-2-20
 * Time: 11:57:50
 * To change this template use File | Settings | File Templates.
 */
public class RecordsetQuery {

    public static void main(String[] args) throws Exception {
          doQuery();
     }


protected static void doQuery() throws Exception {

     SBOErrorMessage errMsg = null;
     ICompany com = null;
     IRecordset RecSet = null;
     int i;
     String FldName;
     String FldVal;
     Object index;

     String sQueryItemList1 = "Select TargetType,TrgetEntry,LineStatus,OpenQty,OpenCreQty From RDR1";

     JcoConn conn = new JcoConn();

     int rc = conn.conn();
     if (rc == 0) {

          try {
          RecSet =
               SBOCOMUtil.runRecordsetQuery(
               conn.getCompany(),
               sQueryItemList1);
          int Count = RecSet.getFields().getCount().intValue();
          while (RecSet.isEoF().equals(new Boolean(false))) {
               for (i = 0; i < Count; i++) {
                    index = new Integer(i);
                    FldName = RecSet.getFields().item(index).getName();
                                           FldVal =     String.valueOf(RecSet.getFields().item(index).getValue());
                    //'Here you can manipulate the data as you want
                    System.out.println(i + "FldName = " + FldName);
                    System.out.println(i + "FldVal = " + FldVal);
               }

               //Move to the next record
               RecSet.moveNext();
              
          }
     } catch (Exception ex) {
          errMsg = conn.getCompany().getLastError();
          ex.printStackTrace();
     }
    }
    RecSet = null;
    com = null;
  }
}